<?php
namespace App\Http\Controllers\Property;


use App\Common\data;
use App\Http\Controllers\Controller;
use Illuminate\Support\Facades\DB;

class DataController extends Controller{

    public  function second($release_id){

    $data = DB::table('release_topic')
        ->select('head','nickname','releasetopic_content','userID','releasetopic_id','release_releasetopic','user_releasetopic')
        ->leftjoin('user','release_topic.user_releasetopic','=','user.user_id')
        ->where('release_releasetopic',$release_id)
        ->orderby('releasetopic_id','ASE')
        ->get();

    return $data;
    }

    public  function secos($release_id){
        $data = DB::table('release_topic')
            ->select('head','nickname','releasetopic_content','userID','releasetopic_id','release_releasetopic','user_releasetopic')
            ->leftjoin('user','release_topic.userID','=','user.user_id')
            ->where('release_releasetopic',$release_id)
            ->orderby('releasetopic_id','ASE')
            ->get();

        return $data;

    }

    public function data(){
        $table     ="user";
        $select    = array('user_id','release_id');

        //$update    = array('phone'=>155,'pass'=>1);

    }


    public function test2($name,$result=array())
    {
        global $result;
        $res    = '';
        $data = $this->second($name);
        foreach ($data as $key => $val) {
            for ($i=0; $i<count($result);$i++) {
                $id =  $result[$i]['releasetopic_id'];
                $d  = $this ->secos($id);
                foreach ($d as $v){
                    $res = $v ->nickname;
                }
            }
                $result[] = array(
                    'head' => $val->head,
                    'nickname' => $val->nickname,
                    'releasetopic_content' => $val->releasetopic_content,
                    'release_releasetopic' => $val->release_releasetopic,
                    'userID' => $val->userID,
                    'nickname1' =>$res,
                    'user_releasetopic' =>$val ->user_releasetopic,
                    'releasetopic_id' => $val->releasetopic_id,
                );

                $this->test2($val->releasetopic_id);

        }
      return $result;
    }

}